home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-03-20 | 16.8 KB | 606 lines | [TEXT/MPS ] |
- /*____________________________________________________
-
- Sample routines for sending status to the desktop
- printer window, and handling user alerts.
-
- Apple Computer, Inc.
- Copyright ©1991 - 1994
-
- 5/04/94 - dmh - Verified for the f2 seed.
- 3/22/94 - dmh - Verified for the b4 seed.
- 3/22/94 - dmh - Filled out statusOwner fields!
- 12/20/93 - dmh - Updated for the b3 seed.
- 9/13/93 - dmh - Updated for the b2 seed.
-
- Note: Descriptions are listed in the "Mark" menu.
-
- ___________________________________________________ */
-
- // Sample code for writing status to the desktop printer window.
-
-
- #define kTransmissionStatID 1
- #define kOpeningConnectionStatIdx 8
-
-
- anErr = GXReportStatus(kTransmissionStatID, kOpeningConnectionStatIdx);
-
-
- resource 'stat' (kTransmissionStatID, sysheap, purgeable)
- {
- kDrvrCreatorType,
- {
- informationalStatus, 0, kNoAlertAlertID, "Sending part of the page…";
- informationalStatus, 0, kNoAlertAlertID, "Preparing part of the page…";
- userAlert, kChangeCarouselsDlogID, kNoAlertAlertID, "Please load the appropriate pen.";
- informationalStatus, 0, kNoAlertAlertID, "A print test is in progress. Please wait…";
- userAlert, 0, kBadTonerCartridgeAlertID, "The toner cartridge is improperly loaded.";
- informationalStatus, 0, kNoAlertAlertID, "Printing the page.";
- userAlert, 0, kCantFindPrinterAlertID, "Trying to locate the printer…";
- openConnectionStatus, 0, kNoAlertAlertID, "Opening a connection to the printer…";
- }
- };
-
-
-
- // Alerts GX already handles -
- //
- // manual feed
- // paper jam
- // failed to print
- // printer ready
- // out of paper
- // no paper tray
- // alert me before printing
- // alert me after printing
- //
- // PrintingDrivers.h has constants you need for this
-
-
-
- // Sample code for "Manual Feed Alert" - one that we help you with
-
- //
- //
- // DoManualFeedDialog
- //
- // This function will present a manual feed dialog to the user. In this
- // example we have a printer that is smart enough to know if the user has
- // placed paper in the manual feed slot. This printer will also allow the
- // user to decide to switch to automatic feed at dialog time.
- //
- // The driver must allocate a status record with a buffer that will contain
- // the gxManualFeedRecord. This record contains the name of the papertype
- // which needs to be fed. This will be displayed in the dialog. The record
- // also contains a boolean that tells the printing manager whether the dialog should
- // contain the automatic feed button.
- //
- // The driver fills in the statResId and statResIndex fields of the status record
- // to indicate that the desired stat resource belongs to the universal driver and
- // the particular alert is for manual feed. The papertype name is filled in.
- //
- // The driver then calls GXAlertTheUser which will display the dialog. The driver
- // continues to call GXAlertTheUser until an error is returned or the user selects
- // one of the buttons in the dialog ( ok, cancel or autoFeed ). Because this printer
- // is so smart, it can tell if the user fed paper without having the user select
- // any button. The driver checks for this case in the loop. If this case is detected,
- // the driver makes a last call to GXAlertTheUser to tell the Printing Manager to
- // remove the dialog. Once the user selects any button in the dialog, the dialog
- // is automatically dismissed. The dialog is also dismissed when any error is returned.
- //
- // The driver examines the dialogResult field of the status record to see which
- // option the user has selected.
- //
- // Before exiting the routine, the status record pointer is disposed.
- //
- // Note that the CheckToSeeIfPaperWasFed routine must be supplied by the driver.
- //
- //
-
-
- OSErr DoManualFeedDialog()
- {
- OSErr anErr;
- gxStatusRecord *pStatus;
-
- // allocate the status record
-
- pStatus = (Ptr) NewPtrClear(sizeof(gxStatusRecord) + gxManualFeedStatusBufferSize);
- anErr = MemError();
-
- if (anErr == noErr ) {
-
- gxManualFeedRecord *mfeedInfo;
-
- pStatus->statusOwner = kDrvrCreatorType;
- pStatus->statResId = gxUnivAlertStatusResourceId;
- pStatus->statResIndex = gxUnivManualFeedIndex;
- pStatus->bufferLen = gxManualFeedStatusBufferSize;
-
- mfeedInfo = (gxManualFeedRecord *) &pStatus->statusBuffer;
- mfeedInfo->canAutoFeed = true;
- GXGetPaperTypeName(thePaperType, mfeedInfo->paperTypeName);
-
-
- // Tell the Printing Manager to display the manual feed alert
-
- do
- {
-
- anErr = GXAlertTheUser(pStatus);
-
- // see if the user has loaded the paper
-
- if ((anErr == noErr) && (pStatus->dialogResult == nil)) {
-
- Boolean userFedPaper;
-
- userFedPaper = CheckToSeeIfPaperWasFed();
- if (userFedPaper) {
- pStatus->statResIndex = gxUnivPrinterReadyIndex;
- anErr = GXAlertTheUser(pStatus);
- pStatus->dialogResult = ok;
-
- }
- }
-
- } while ((pStatus->dialogResult == nil) && (anErr == noErr));
-
-
- // act on the dialog result
-
- if (anErr == noErr) {
-
- switch (pStatus->dialogResult) {
-
- gxOKSelected: PrintThePageManually();
- break;
-
- gxCancelSelected: anErr = gxPrUserAbortErr;
- break;
-
- gxAutoFeedButtonId: PrintThePageAutomatically();
- break;
- }
- }
- DisposePtr( pStatus );
- }
- return( anErr );
- }
-
-
-
- // Sample code for "Printer Not Responding" - one you do yourself
-
- //
- //
- // HandleOpenConnection
- //
- // This function will attempt to open a connection to the printer. If it fails
- // it will send an alert to the user.
- //
- // The driver supplies a 'cool' Alert resource. The stat resource referenced by
- // the status record that the driver builds will reference this cool alert.
- // Note that the cool alert has place holders for strings. The printing manager
- // will fill these strings in with the name of the printer and the document. This
- // is the default behavior when a cool alert is referenced with these placeholders.
- // !0 will be replaced with the printer name. !1 will be replaced with the document
- // name. !2 will be replaced with any papertype name sent.
- //
- // The driver must allocate a status record with a default buffer that will be used
- // internally by the printing manager.
- //
- // The driver fills in the statResId and statResIndex fields of the status record
- // to indicate that the desired stat resource belongs to the driver and
- // the particular alert informs the user that the printer cannot be found.
- //
- // The driver then calls GXAlertTheUser which will display the dialog. The driver
- // continues to call GXAlertTheUser until an error is returned or the user selects
- // the Abort button. The driver continues to look for the printer while the
- // alert is up. If the printer is found, the driver calls GXAlertTheUser a final
- // time to remove the dialog. If the user selects the Abort button, the dialog
- // is automatically dismissed. The dialog is also dismissed when any error is returned.
- //
- // The driver examines the dialogResult field of the status record to see which
- // option the user has selected.
- //
- // Before exiting the routine, the status record pointer is disposed.
- //
- // Note that the TryToOpenConnection routine must be supplied by the driver.
- //
- //
-
- #define kTransmissionStatID 1
- #define kCantFindPrinterStatIdx 7
-
-
- OSErr HandleOpenConnection()
- {
- OSErr anErr;
- gxStatusRecord *pStatus;
-
-
- anErr = TryToOpenConnection();
-
- if (anErr == gxAioCantFindDevice) // T => Can't locate device; tell user to turn it on
- {
- // Now we set-up to alert the user that the printer cannot be found
- // Allocate a status record large enough to handle status with the largest
- // buffer size.
-
- pStatus = (Ptr) NewPtrClear(sizeof(gxStatusRecord) + gxDefaultStatusBufferSize);
- anErr = MemError();
- if (anErr == noErr) {
-
- // Initialize the appropriate fields within the status record
-
- pStatus->statusOwner = kDrvrCreatorType;
- pStatus->statResId = kTransmissionStatID;
- pStatus->statResIndex = kCantFindPrinterStatIdx;
- pStatus->bufferLen = gxDefaultStatusBufferSize;
-
- // Now display the alert to the user
- do
- {
- anErr = GXAlertTheUser(pStatus);
- if ((anErr == noErr) && (pStatus->dialogResult == nil))
- { // Try looking for the device again
- anErr = TryToOpenConnection();
- }
- }
- while ( (anErr == gxAioCantFindDevice) && (pStatus->dialogResult == nil) );
-
- // If the user dismissed the dialog, we are to abort the job
- if (pStatus->dialogResult != nil)
- anErr = gxPrUserAbortErr;
-
- else // another error (possible timeout) or success
- {
- pStatus->statResId = gxUnivAlertStatusResourceId;
- pStatus->statResIndex = gxUnivPrinterReadyIndex;
- GXAlertTheUser(pStatus); // Tell GX to remove the alert
- }
-
- // Kill the status pointer
- DisposPtr((Ptr) pStatus);
- }
- }
-
- return( anErr );
- }
-
-
- resource 'plrt' (kCantFindPrinterAlertID, sysheap, purgeable)
- { // The printer can't be found on the
- // SCSI bus
- printingStatus, // version
- cautionIcon, // icon id
- defaultSystemSize,
- defaultAction, // the default label
- noCancelTitle, // no cancel
- "The document !1 cannot be printed, because the printer "
- "!0 cannot be found. To continue printing, please make "
- "sure the printer is "
- "properly connected and turned on. If you wish "
- "to cancel printing, please click Abort Job.",
- "Abort Job", // action label
- "", // button label 2
- "", // button label 3
- " " // font name
- };
-
-
-
- // Sample code for "Plotter Carousel Change" Alert - one you do yourself
-
- //
- //
- // HandleCarouselChange
- //
- // This function will initiate a dialog with the user asking the user to
- // place the appropriate carousel in the plotter.
- //
- // The dialog that will be displayed to the user is not a cool alert. The
- // driver needs to supply parts of the dialog dynamically - the name of the
- // carousel and the names of the pens it hopes to find there. These names
- // are stored in the buffer in the status record. The driver allocates the
- // status record with a buffer larger enough to hold these strings. It then
- // fills in the strings.
- //
- // The driver fills in the statResId and statResIndex fields of the status record
- // to indicate that the desired stat resource belongs to the driver and
- // the particular alert informs the user that the print carousel needs to be changed.
- //
- // The driver then calls GXAlertTheUser which will display the dialog. The driver
- // continues to call GXAlertTheUser until an error is returned or the user selects
- // the Abort one of the buttons in the dialog.
- //
- // In order to conduct this dialog, the driver must override 2 messages -
- // InitializeStatusAlert - to create the dialog and
- // HandleAlertEvent - to handle dialog events
- //
- // The driver examines the dialogResult field of the status record to see which
- // option the user has selected.
- //
- // Before exiting the routine, the status record pointer is disposed.
- //
- // Note that the FillInCarouselInfo routine must be supplied by the driver.
- //
- //
-
- #define kTransmissionStatID 1
- #define kLoadPenIdx 3
-
- typedef struct {
- Str31 carouselName;
- Str15 penName1;
- Str15 penName2;
- Str15 penName3;
- Str15 penName4;
- } CarouselInfo;
-
- OSErr HandleCarouselChange()
- {
- OSErr anErr;
- gxStatusRecord *pStatus;
-
-
- // Allocate a status record large enough to handle status with the a
- // buffer to hold the CarouselInfo structure.
-
- pStatus = (Ptr) NewPtrClear(sizeof(gxStatusRecord) + sizeof( CarouselInfo ));
- anErr = MemError();
- if (anErr == noErr) {
-
-
- // fill in the status buffer will carousel name and pen names
-
- FillInCarouselInfo( pStatus );
-
- // Initialize the appropriate fields within the status record
-
- pStatus->statusOwner = kDrvrCreatorType;
- pStatus->statResId = kTransmissionStatID;
- pStatus->statResIndex = kLoadPenIdx;
- pStatus->bufferLen = sizeof( CarouselInfo );
-
- // Now display the alert to the user
- do
- {
- anErr = GXAlertTheUser(pStatus);
- }
- while ( (anErr == noErr) && (pStatus->dialogResult == nil) );
-
- // Act on result
-
- if (pStatus->dialogResult != nil) {
-
- switch (pStatus->dialogResult)
-
- ok: HandleChange();
- break;
-
- cancel: HandleCancel();
- break;
-
- holdRequest: HandleHold();
- break;
-
- }
-
- // Kill the status pointer
- DisposPtr((Ptr) pStatus);
- }
-
- return( anErr );
- }
-
-
- //
- // MyInitializeStatusAlert
- //
- // This routine is called when overriding InitializeStatusAlert
- //
- // Since this is a message, the first thing the driver does is see if this
- // message is intended for the driver by checking the owner field in the
- // status record. If the owner is not the driver, the message is forwarded.
- //
- // In the case that the driver is the owner, the driver checks the status id
- // to see which alert needs to be created. The driver calls GetNewDialog on
- // the appropriate resource and then calls a routine to dynamically fill in
- // the static text strings in the dialog. These strings are stored in the
- // status buffer in the status record.
- //
- // On the return, the Finder will display the dialog referenced through the
- // pDialog parameter.
- //
- //
-
- OSErr MyInitializeStatusAlert( gxStatusRecordPtr pStatus, DialogPtr *pDialog )
- {
- OSErr anErr = noErr;
-
- // first see if this message is for you
-
- if (pStatus->statusOwner == kDrvrCreatorType) {
-
- if (pStatus->statusId == kChangeCarouselsDlogID) {
-
- *pDialog = GetNewDialog( kChangeCarouselsDlogID, nil, (WindowPtr)-1);
- if (*pDialog == nil)
- anErr = resNotFound;
- else
- FillInDialogStrings( pStatus, pDialog );
-
-
-
- }
- else...
-
-
- }
-
- else // it belongs to someone else
- Forward_GXInitializeStatusAlert( pStatus, pDialog );
-
- return( anErr );
- }
-
-
- //
- // MyHandleAlertEvent
- //
- // This routine is called when overriding HandleAlertEvent
- //
- // Since this is a message, the first thing the driver does is see if this
- // message is intended for the driver by checking the owner field in the
- // status record. If the owner is not the driver, the message is forwarded.
- //
- // In the case that the driver is the owner, the driver checks the status id
- // to see which alert is being conducted. The driver then examines the event
- // for the alert. If the user dismisses the dialog by selecting a dialog
- // button, this result is recorded in the status record.
- //
- // On the return, the Finder will dismiss the dialog if the dialogResult field
- // is not nil. The dialog is also dismissed when any error is returned.
- //
- // Note that a driver may use the status buffer for any purpose it needs to. For
- // example, if the driver needed more information returned from this dialog, it
- // could be stored in the buffer.
- //
- // Note that the HandleCarouselDialogEvent is supplied by the driver.
- //
- //
- OSErr MyHandleAlertEvent( gxStatusRecordPtr pStatus, DialogPtr *pDialog,
- EventRecord *theEvent, short *itemHit )
- {
- OSErr anErr = noErr;
-
- // first see if this message is for you
-
- if (pStatus->statusOwner == kDrvrCreatorType) {
-
- if (pStatus->statusId == kChangeCarouselsDlogID) {
-
- HandleCarouselDialogEvent( pDialog, theEvent, itemHit );
- pStatus->dialogResult = *itemHit;
-
-
- }
- else...
-
-
- }
-
- else // it belongs to someone else
- Forward_GXHandleAlertEvent( pStatus, pDialog, theEvent, itemHit );
-
- return( anErr );
- }
-
-
- #define SystemSevenOrLater true
-
- resource 'DLOG' (kChangeCarouselsDlogID, sysheap, purgeable) {
- {50, 10, 310, 440},
- movableDBoxProc,
- invisible,
- noGoAway,
- 0x0,
- kChangeCarouselsDlogID,
- "",
- centerMainScreen
- };
-
-
- resource 'DITL' (kChangeCarouselsDlogID, sysheap, purgeable) {
- { /* array DITLarray: 14 elements */
- /* [1] */
- {234, 335, 254, 415},
- Button {
- enabled,
- "Continue"
- },
- /* [2] */
- {234, 178, 254, 320},
- Button {
- enabled,
- "Cancel print request"
- },
- /* [3] */
- {234, 10, 254, 165},
- Button {
- enabled,
- "Place request on Hold"
- },
- /* [4] */
- {20, 60, 68, 410},
- StaticText {
- disabled,
- "Please place the ^0 carousel in the plotter. Make sure the "
- "plotter is finished with the current set of pens before "
- "making the change."
- },
- /* [5] */
- {105, 30, 198, 207}, // Rectangle that bounds the image of the carousel
- UserItem {
- disabled
- },
- /* [6] */
- {90, 215, 106, 235},
- StaticText {
- enabled,
- "1."
- },
- /* [7] */
- {90, 240, 106, 400}, // Pen #1 name
- StaticText {
- enabled,
- ""
- },
- /* [8] */
- {106, 215, 122, 235},
- StaticText {
- enabled,
- "2."
- },
- /* [9] */
- {106, 240, 122, 400}, // Pen #2 name
- StaticText {
- enabled,
- ""
- },
- /* [10] */
- {122, 215, 138, 235},
- StaticText {
- enabled,
- "3."
- },
- /* [11] */
- {122, 240, 138, 400}, // Pen #3 name
- StaticText {
- enabled,
- ""
- },
- /* [12] */
- {138, 215, 154, 235},
- StaticText {
- enabled,
- "4."
- },
- /* [13] */
- {138, 240, 154, 400}, // Pen #4 name
- StaticText {
- enabled,
- ""
- },
- /* [14] */
- {20, 9, 52, 41}, // Stop icon
- Icon {
- disabled,
- 2
- },
- }
- };
-
-